package com.xinsoft.controller.outsourcing;

import com.xinsoft.common.Response;
import com.xinsoft.entity.dto.ScmOutsourcingContractParam;
import com.xinsoft.entity.dto.ScmOutsourcingFeedingItemParam;
import com.xinsoft.entity.dto.ScmOutsourcingFeedingParam;
import com.xinsoft.entity.vo.ScmOutsourcingContractPageVo;
import com.xinsoft.entity.vo.ScmOutsourcingFeedingDetailVo;
import com.xinsoft.entity.vo.ScmOutsourcingFeedingPageVo;
import com.xinsoft.service.ScmOutsourcingFeedingService;
import com.xinsoft.utils.TokenUtil;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

/**
 * 委外投料
 *
 * @folder 云供应链/委外管理/委外投料
 */
@RestController
@RequestMapping("/scm/outsourcingFeeding")
public class ScmOutsourcingFeedingController {
    @Autowired
    private ScmOutsourcingFeedingService outsourcingFeedingService;

    /**
     * 分页
     */
    @PostMapping("/pageList")
    public Response<?> pageList(@RequestBody ScmOutsourcingFeedingParam param) {
        return Response.succeed(outsourcingFeedingService.findPageListByParam(param));
    }

    // @PostMapping("/pageList1")
    // public ScmOutsourcingFeedingPageVo pageList1(@RequestBody ScmOutsourcingFeedingParam param) {
    //     return null;
    // }


    /**
     * 投料子物料列表
     */
    @PostMapping("/childList")
    public Response<?> childList(@RequestBody ScmOutsourcingFeedingItemParam param) {
        return Response.succeed(outsourcingFeedingService.childList(param));
    }

    /**
     * 获取详情
     *
     * @param id 销售订单id
     * @return {@link Response}<{@link ?}>
     */
    @GetMapping("/detail")
    public Response<?> detail(@RequestParam(value = "id") Integer id) {
        ScmOutsourcingFeedingDetailVo vo = outsourcingFeedingService.detail(id);
        return Response.succeed(vo);
    }

    /**
     * 审核
     */
    @PostMapping("/audit")
    @Transactional(rollbackFor = Exception.class)
    public Response<?> audit(@ApiParam(value = "委外投料单id", required = true) @RequestParam("id") Integer id) {
        outsourcingFeedingService.audit(id);
        return Response.succeed();
    }

    /**
     * 反审核
     */
    @PostMapping("/reverseAudit")
    @Transactional(rollbackFor = Exception.class)
    public Response<?> reverseAudit(@ApiParam(value = "委外投料单id", required = true) @RequestParam("id") Integer id) {
        outsourcingFeedingService.reverseAudit(id);
        return Response.succeed();
    }
}
